from fastapi import Depends, APIRouter, routing
from app.common.http.http_result import Success, Error
from app.common.http.http_status import HttpStatus
from models.user_model import UserScheme, UserLogin
from services.user_service import UserService, get_user_service

router = APIRouter(prefix="/app", tags=["app"])


@router.post("/login")
async def do_login(user: UserLogin, service: UserService = Depends(get_user_service)):
    target = service.get_user_by_account(user.account)
    if not target:
        return Error('用户名或密码错误！', code=HttpStatus.NOT_AUTHOR)
    if target.password != user.password:
        return Error('用户名或密码错误！', code=HttpStatus.NOT_AUTHOR)

    # todo 生成jwt
    return Success("登录成功！")


# @router.post("/logout")
# async def list_users(page: int, page_size: int, service: UserService = Depends(get_user_service)):
#     return service.list_users(page, page_size)
